Echo = $FFEF
Monitor = $FF1F


  LDX #$00          ;  Initialize counter to 0
  JMP start         ;  Skip over increment first time through the loop

next:
  INX               ;  Increment the counter
start:
  TXA               ;  printbin2 requires the value be in the accumulator
  JSR printbin2     ;  print the value as binary
  CPX #$FF          ;  If we've reached 255 ($FF), we're done
  BNE next          ;  If not, loop again

  JMP Monitor
  
  

/*
Name:               PrintBin2
Precondtions:       Byte to print is in Accumulator.
Postcondtions:      The string is printed to screen.
Destroys:           Flags
Description:        Prints the binary representation of the value in A.
*/

printbin2:

  STA temp
  PHA               ;  Puch Accumulator
  TXA
  PHA               ;  Push X
  TYA               ;  Push Y
  PHA
  LDA temp

  LDY #$00          ;  Initialize counter to 0
  ROR               ;  ROR once so initial setup will mesh with the loop
  TAX               ;  Loop expects value to be in X register

begin:
  TXA               ;  Restore value to Accumulator
  ROL               ;  Rotate next bit into bit 7's location
  BMI neg           ;  If that bit is a 1, then branch to neg
  TAX               ;  The bit is 0; save byte to X
  LDA #$30          ;  Load ASCII '0' for printing
  JSR Echo          ;  Print 0
  JMP continue      ;  Skip over code for printing a 1
neg:
  TAX               ;  Save byte to X
  LDA #$31          ;  Load ASCII '1' for printing
  JSR Echo          ;  Print 1

continue:
  INY               ;  Increment counter
  CPY #$08          ;  Compare counter to 8 (number of bits to print + 1)
  BNE begin         ;  If counter != 8, then not all bits have been printed,
                    ;  so loop again, otherwise continue
                    
  LDA #$0D          ;  Load ASCII Carriage Return (CR)
  JSR Echo          ;  Print CR to screen
  
  

  PLA
  TAY               ;  Recover Y
  PLA
  TAX               ;  Recover X
  PLA               ;  Recover Accumulator
  
  RTS               ;  Exit subroutine
  
temp:
  .asc $00          ;  Temporary storage location for Accumulator preservation
  
  